<html>
<head>
  <title>Evernote Export</title>
  <basefont face="微软雅黑" size="2" />
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  <meta name="exporter-version" content="Evernote Windows/304720 (zh-CN, DDL); Windows/10.0.14393 (Win64);"/>
  <style>
    body, td {
      font-family: 微软雅黑;
      font-size: 10pt;
    }
  </style>
</head>
<body>
<a name="3313"/>
<h1>9、数据转换 &amp; 数据格式化 &amp; 数据校验</h1>
<div>
<table bgcolor="#D4DDE5" border="0">
<tr><td><b>创建时间：</b></td><td><i>2017/6/23 9:24</i></td></tr>
<tr><td><b>更新时间：</b></td><td><i>2017/6/23 15:51</i></td></tr>
<tr><td><b>作者：</b></td><td><i>雷丰阳</i></td></tr>
</table>
</div>
<br/>

<div>
<span><ul><li><span style="font-size:20.0pt;font-family:&quot;Arial Unicode MS&quot;;mso-ascii-font-family: &quot;Arial Unicode MS&quot;;mso-fareast-font-family:&quot;Arial Unicode MS&quot;;mso-bidi-font-family: &quot;Arial Unicode MS&quot;;color:red;mso-font-kerning:12.0pt;language:zh-CN;font-weight: bold;mso-style-textfill-type:solid;mso-style-textfill-fill-color:red; mso-style-textfill-fill-alpha:100.0%">数据转换</span> <span style="font-size:20.0pt; font-family:&quot;Arial Unicode MS&quot;;mso-ascii-font-family:&quot;Arial Unicode MS&quot;; mso-fareast-font-family:&quot;Arial Unicode MS&quot;;mso-bidi-font-family:&quot;Arial Unicode MS&quot;; color:black;mso-color-index:1;mso-font-kerning:12.0pt;language:en-US; mso-style-textfill-type:solid;mso-style-textfill-fill-themecolor:text1; mso-style-textfill-fill-color:black;mso-style-textfill-fill-alpha:100.0%">&amp;</span> <span style="font-size:20.0pt;font-family:&quot;Arial Unicode MS&quot;;mso-ascii-font-family: &quot;Arial Unicode MS&quot;;mso-fareast-font-family:&quot;Arial Unicode MS&quot;;mso-bidi-font-family: &quot;Arial Unicode MS&quot;;color:black;mso-color-index:1;mso-font-kerning:12.0pt; language:zh-CN;mso-style-textfill-type:solid;mso-style-textfill-fill-themecolor: text1;mso-style-textfill-fill-color:black;mso-style-textfill-fill-alpha:100.0%">数据格式</span><span style="font-size:20.0pt;font-family:&quot;Arial Unicode MS&quot;;mso-ascii-font-family: &quot;Arial Unicode MS&quot;;mso-fareast-font-family:&quot;Arial Unicode MS&quot;;mso-bidi-font-family: &quot;Arial Unicode MS&quot;;color:black;mso-color-index:1;mso-font-kerning:12.0pt; language:zh-CN;mso-style-textfill-type:solid;mso-style-textfill-fill-themecolor: text1;mso-style-textfill-fill-color:black;mso-style-textfill-fill-alpha:100.0%">化</span><span style="font-size:20.0pt;font-family:&quot;Arial Unicode MS&quot;;mso-ascii-font-family: &quot;Arial Unicode MS&quot;;mso-fareast-font-family:&quot;Arial Unicode MS&quot;;mso-bidi-font-family: &quot;Arial Unicode MS&quot;;color:black;mso-color-index:1;mso-font-kerning:12.0pt; language:en-US;mso-style-textfill-type:solid;mso-style-textfill-fill-themecolor: text1;mso-style-textfill-fill-color:black;mso-style-textfill-fill-alpha:100.0%">&amp;</span> <span style="font-size:20.0pt;font-family:&quot;Arial Unicode MS&quot;; mso-ascii-font-family:&quot;Arial Unicode MS&quot;;mso-fareast-font-family:&quot;Arial Unicode MS&quot;; mso-bidi-font-family:&quot;Arial Unicode MS&quot;;color:black;mso-color-index:1; mso-font-kerning:12.0pt;language:zh-CN;mso-style-textfill-type:solid; mso-style-textfill-fill-themecolor:text1;mso-style-textfill-fill-color:black; mso-style-textfill-fill-alpha:100.0%">数据</span><span style="font-size:20.0pt; font-family:&quot;Arial Unicode MS&quot;;mso-ascii-font-family:&quot;Arial Unicode MS&quot;; mso-fareast-font-family:&quot;Arial Unicode MS&quot;;mso-bidi-font-family:&quot;Arial Unicode MS&quot;; color:black;mso-color-index:1;mso-font-kerning:12.0pt;language:zh-CN; mso-style-textfill-type:solid;mso-style-textfill-fill-themecolor:text1; mso-style-textfill-fill-color:black;mso-style-textfill-fill-alpha:100.0%">校验；</span></li></ul><div><font face="Arial Unicode MS" size="6">SpringMVC封装自定义类型对象的时候？</font></div><div><font face="Arial Unicode MS" size="6">javaBean要和页面提交的数据进行一一绑定？</font></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">1）、页面提交的所有数据都是字符串？</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">2）、Integer age,Date birth;</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">          employName=zhangsan&amp;age=18&amp;gender=1</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">          String age = request.getParameter(&quot;age&quot;);<br/></span></span></div><div><font face="Arial Unicode MS" size="6">牵扯到以下操作；</font></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">1）、数据绑定期间的数据类型转换？String--Integer String--Boolean,xxx</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">2）、数据绑定期间的数据格式化问题？比如提交的日期进行转换</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">               birth=2017-12-15-----&gt;Date    2017/12/15  2017.12.15  2017-12-15<br/></span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">3）、数据校验？</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">               我们提交的数据必须是合法的？</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">               前端校验：js+正则表达式；</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">               后端校验：重要数据也是必须的；</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">               1）、校验成功！数据合法</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">               2）、校验失败？</span></span></div><div><hr/></div><div>新的源码；</div><div>ModelAttributeMethodProcessor</div><div align="left" style="min-height: 18pt;"><font color="#7F0055" face="Consolas" size="4"><span style="font-size:16pt"><b>public</b></span></font> <font color="#7F0055" face="Consolas" size="4"><span style="font-size:16pt"><b>final</b></span></font> <font face="Consolas" size="4"><span style="font-size:16pt">Object resolveArgument(</span></font></div><div align="left" style="min-height: 18pt;"><font face="Consolas" size="4"><span style="font-size:16pt">            MethodParameter parameter, ModelAndViewContainer mavContainer,</span></font></div><div align="left" style="min-height: 18pt;"><font face="Consolas" size="4"><span style="font-size:16pt">            NativeWebRequest request, WebDataBinderFactory binderFactory)</span></font></div><div align="left" style="min-height: 18pt;"><font face="Consolas" size="4"><span style="font-size:16pt">            </span></font><font color="#7F0055" face="Consolas" size="4"><span style="font-size:16pt"><b>throws</b></span></font> <font face="Consolas" size="4"><span style="font-size:16pt">Exception {</span></font></div><div align="left" style="min-height: 18pt;"><font face="Consolas" size="4"><span style="font-size:16pt">        String name = ModelFactory.</span><span style="font-size:16pt"><i>getNameForParameter</i></span><span style="font-size:16pt">(parameter);</span></font></div><div align="left" style="min-height: 18pt;"><font face="Consolas" size="4"><span style="font-size:16pt">        Object attribute = (mavContainer.containsAttribute(name)) ?</span></font></div><div align="left" style="min-height: 11pt;"><font face="Consolas" size="4"><span style="font-size:16pt">                mavContainer.getModel().get(name) : createAttribute(name, parameter, binderFactory, request);</span></font></div><div align="left" style="min-height: 18pt;"><font face="Consolas" size="4"><span style="font-size:16pt">        WebDataBinder binder = binderFactory.createBinder(request, attribute, name);</span></font></div><div align="left" style="min-height: 18pt;"><div><font face="Consolas" size="4"><span style="font-size:16pt">        </span></font><font color="#7F0055" face="Consolas" size="4"><span style="font-size:16pt"><b>if</b></span></font> <font face="Consolas" size="4"><span style="font-size:16pt">(binder.getTarget() !=</span></font> <font color="#7F0055" face="Consolas" size="4"><span style="font-size:16pt"><b>null</b></span></font><font face="Consolas" size="4"><span style="font-size:16pt">) {</span></font></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;">               将页面提交过来的数据封装到javaBean的属性中<br/></span></span></div></div><div align="left" style="min-height: 18pt;"><font face="Consolas" size="4"><span style="font-size:16pt">           <b> bindRequestParameters(binder, request);</b></span></font></div><div align="left" style="min-height: 18pt;"><font face="Consolas" size="4"><span style="font-size:16pt; background:#c6dbae">            validateIfApplicable(binder, parameter);</span></font></div><div align="left" style="min-height: 18pt;"><font face="Consolas" size="4"><span style="font-size:16pt">            </span></font><font color="#7F0055" face="Consolas" size="4"><span style="font-size:16pt"><b>if</b></span></font> <font face="Consolas" size="4"><span style="font-size:16pt">(binder.getBindingResult().hasErrors()) {</span></font></div><div align="left" style="min-height: 18pt;"><font face="Consolas" size="4"><span style="font-size:16pt">                </span></font><font color="#7F0055" face="Consolas" size="4"><span style="font-size:16pt"><b>if</b></span></font> <font face="Consolas" size="4"><span style="font-size:16pt">(isBindExceptionRequired(binder, parameter)) {</span></font></div><div align="left" style="min-height: 18pt;"><font face="Consolas" size="4"><span style="font-size:16pt">                    </span></font><font color="#7F0055" face="Consolas" size="4"><span style="font-size:16pt"><b>throw</b></span></font> <font color="#7F0055" face="Consolas" size="4"><span style="font-size:16pt"><b>new</b></span></font> <font face="Consolas" size="4"><span style="font-size:16pt">BindException(binder.getBindingResult());</span></font></div><div align="left" style="min-height: 18pt;"><font face="Consolas" size="4"><span style="font-size:16pt">                }</span></font></div><div align="left" style="min-height: 18pt;"><font face="Consolas" size="4"><span style="font-size:16pt">            }</span></font></div><div align="left" style="min-height: 18pt;"><div><font face="Consolas" size="4"><span style="font-size:16pt">        }</span></font></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><br/></span></span></div><div><hr/></div><div align="left" style="min-height: 18pt;"><div><font face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">WebDataBinder：数据绑定器负责数据绑定工作；</span></font></div><div><font face="Consolas"><span style="font-size: 21.33333396911621px;">数据绑定期间产生的类型转换、格式化、数据校验等问题；</span></font></div><div><img src="9、数据转换 & 数据格式化 & 数据校验_files/Image.png" type="image/png" style="height: auto;"/></div><div>ConversionService组件：负责数据类型的转换以及格式化功能；</div><div>          ConversionService中有非常多的<b>converter；</b></div><div>          不同类型的转换和格式化用它自己的<b>converter</b></div></div></div><div align="left" style="min-height: 18pt;"><div><br/></div><div style="-en-codeblock: true; box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial;"><div><b>ConversionService converters =</b></div><div>    @org.springframework.format.annotation.DateTimeFormat java.lang.Long -&gt; java.lang.String: org.springframework.format.datetime.<b>DateTimeFormatAnnotationFormatterFactory</b>@32abc654,@org.springframework.format.annotation.NumberFormat java.lang.Long -&gt; java.lang.String: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@140bb45d</div><div>    @org.springframework.format.annotation.DateTimeFormat java.time.LocalDate -&gt; java.lang.String: org.springframework.format.datetime.standard.Jsr310DateTimeFormatAnnotationFormatterFactory@39274b77,java.time.LocalDate -&gt; java.lang.String : org.springframework.format.datetime.standard.TemporalAccessorPrinter@edd23ab</div><div>    @org.springframework.format.annotation.DateTimeFormat java.time.LocalDateTime -&gt; java.lang.String: org.springframework.format.datetime.standard.Jsr310DateTimeFormatAnnotationFormatterFactory@39274b77,java.time.LocalDateTime -&gt; java.lang.String : org.springframework.format.datetime.standard.TemporalAccessorPrinter@4f10103d</div><div>    @org.springframework.format.annotation.DateTimeFormat java.time.LocalTime -&gt; java.lang.String: org.springframework.format.datetime.standard.Jsr310DateTimeFormatAnnotationFormatterFactory@39274b77,java.time.LocalTime -&gt; java.lang.String : org.springframework.format.datetime.standard.TemporalAccessorPrinter@2b482406</div><div>    @org.springframework.format.annotation.DateTimeFormat java.time.OffsetDateTime -&gt; java.lang.String: org.springframework.format.datetime.standard.Jsr310DateTimeFormatAnnotationFormatterFactory@39274b77,java.time.OffsetDateTime -&gt; java.lang.String : org.springframework.format.datetime.standard.TemporalAccessorPrinter@5bff2a4e</div><div>    @org.springframework.format.annotation.DateTimeFormat java.time.OffsetTime -&gt; java.lang.String: org.springframework.format.datetime.standard.Jsr310DateTimeFormatAnnotationFormatterFactory@39274b77,java.time.OffsetTime -&gt; java.lang.String : org.springframework.format.datetime.standard.TemporalAccessorPrinter@220f2940</div><div>    @org.springframework.format.annotation.DateTimeFormat java.time.ZonedDateTime -&gt; java.lang.String: org.springframework.format.datetime.standard.Jsr310DateTimeFormatAnnotationFormatterFactory@39274b77,java.time.ZonedDateTime -&gt; java.lang.String : org.springframework.format.datetime.standard.TemporalAccessorPrinter@174673c</div><div>    @org.springframework.format.annotation.DateTimeFormat java.util.Calendar -&gt; java.lang.String: org.springframework.format.datetime.DateTimeFormatAnnotationFormatterFactory@32abc654</div><div>    @org.springframework.format.annotation.<b>DateTimeFormat</b> java.util.Date -&gt; java.lang.String: org.springframework.format.datetime.DateTimeFormatAnnotationFormatterFactory@32abc654</div><div>    @org.springframework.format.annotation.NumberFormat java.lang.Double -&gt; java.lang.String: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@140bb45d</div><div>    @org.springframework.format.annotation.<b>NumberFormat</b> java.lang.Float -&gt; java.lang.String: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@140bb45d</div><div>    @org.springframework.format.annotation.NumberFormat java.lang.Integer -&gt; java.lang.String: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@140bb45d</div><div>    @org.springframework.format.annotation.NumberFormat java.lang.Short -&gt; java.lang.String: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@140bb45d</div><div>    @org.springframework.format.annotation.NumberFormat java.math.BigDecimal -&gt; java.lang.String: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@140bb45d</div><div>    @org.springframework.format.annotation.NumberFormat java.math.BigInteger -&gt; java.lang.String: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@140bb45d</div><div>    java.lang.Boolean -&gt; java.lang.String : org.springframework.core.convert.support.ObjectToStringConverter@67fe49bf</div><div>    java.lang.Character -&gt; java.lang.Number : org.springframework.core.convert.support.CharacterToNumberFactory@5184d61b</div><div>    java.lang.Character -&gt; java.lang.String : org.springframework.core.convert.support.ObjectToStringConverter@6a45e172</div><div>    java.lang.Enum -&gt; java.lang.String : org.springframework.core.convert.support.EnumToStringConverter@64048fc3</div><div>    java.lang.Long -&gt; java.util.Calendar : org.springframework.format.datetime.DateFormatterRegistrar$LongToCalendarConverter@37cbfe30</div><div>    java.lang.Long -&gt; java.util.Date : org.springframework.format.datetime.DateFormatterRegistrar$LongToDateConverter@79fc7df4</div><div>    java.lang.Number -&gt; java.lang.Character : org.springframework.core.convert.support.NumberToCharacterConverter@6d7337c1</div><div>    java.lang.Number -&gt; java.lang.Number : org.springframework.core.convert.support.NumberToNumberConverterFactory@6e0b7bd8</div><div>    java.lang.Number -&gt; java.lang.String : org.springframework.core.convert.support.ObjectToStringConverter@1135afc3</div><div>    java.lang.String -&gt; @org.springframework.format.annotation.DateTimeFormat java.lang.Long: org.springframework.format.datetime.DateTimeFormatAnnotationFormatterFactory@32abc654,java.lang.String -&gt; @org.springframework.format.annotation.NumberFormat java.lang.Long: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@140bb45d</div><div>    java.lang.String -&gt; @org.springframework.format.annotation.DateTimeFormat java.time.LocalDate: org.springframework.format.datetime.standard.Jsr310DateTimeFormatAnnotationFormatterFactory@39274b77,java.lang.String -&gt; java.time.LocalDate: org.springframework.format.datetime.standard.TemporalAccessorParser@6228dd42</div><div>    java.lang.String -&gt; @org.springframework.format.annotation.DateTimeFormat java.time.LocalDateTime: org.springframework.format.datetime.standard.Jsr310DateTimeFormatAnnotationFormatterFactory@39274b77,java.lang.String -&gt; java.time.LocalDateTime: org.springframework.format.datetime.standard.TemporalAccessorParser@6bf61650</div><div>    java.lang.String -&gt; @org.springframework.format.annotation.DateTimeFormat java.time.LocalTime: org.springframework.format.datetime.standard.Jsr310DateTimeFormatAnnotationFormatterFactory@39274b77,java.lang.String -&gt; java.time.LocalTime: org.springframework.format.datetime.standard.TemporalAccessorParser@2837beeb</div><div>    java.lang.String -&gt; @org.springframework.format.annotation.DateTimeFormat java.time.OffsetDateTime: org.springframework.format.datetime.standard.Jsr310DateTimeFormatAnnotationFormatterFactory@39274b77,java.lang.String -&gt; java.time.OffsetDateTime: org.springframework.format.datetime.standard.TemporalAccessorParser@60f3f7</div><div>    java.lang.String -&gt; @org.springframework.format.annotation.DateTimeFormat java.time.OffsetTime: org.springframework.format.datetime.standard.Jsr310DateTimeFormatAnnotationFormatterFactory@39274b77,java.lang.String -&gt; java.time.OffsetTime: org.springframework.format.datetime.standard.TemporalAccessorParser@3cb8bdb7</div><div>    java.lang.String -&gt; @org.springframework.format.annotation.DateTimeFormat java.time.ZonedDateTime: org.springframework.format.datetime.standard.Jsr310DateTimeFormatAnnotationFormatterFactory@39274b77,java.lang.String -&gt; java.time.ZonedDateTime: org.springframework.format.datetime.standard.TemporalAccessorParser@14a1511f</div><div>    java.lang.String -&gt; @org.springframework.format.annotation.DateTimeFormat java.util.Calendar: org.springframework.format.datetime.DateTimeFormatAnnotationFormatterFactory@32abc654</div><div>    java.lang.String -&gt; @org.springframework.format.annotation.DateTimeFormat java.util.Date: org.springframework.format.datetime.DateTimeFormatAnnotationFormatterFactory@32abc654</div><div>    java.lang.String -&gt; @org.springframework.format.annotation.NumberFormat java.lang.Double: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@140bb45d</div><div>    java.lang.String -&gt; @org.springframework.format.annotation.NumberFormat java.lang.Float: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@140bb45d</div><div>    java.lang.String -&gt; @org.springframework.format.annotation.NumberFormat java.lang.Integer: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@140bb45d</div><div>    java.lang.String -&gt; @org.springframework.format.annotation.NumberFormat java.lang.Short: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@140bb45d</div><div>    java.lang.String -&gt; @org.springframework.format.annotation.NumberFormat java.math.BigDecimal: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@140bb45d</div><div>    java.lang.String -&gt; @org.springframework.format.annotation.NumberFormat java.math.BigInteger: org.springframework.format.number.NumberFormatAnnotationFormatterFactory@140bb45d</div><div>    <b>java.lang.String -&gt; java.lang.Boolean</b> : org.springframework.core.convert.support.<b>StringToBooleanConverter</b>@22f562e2</div><div>   <b> java.lang.String -&gt; java.lang.Character</b> : org.springframework.core.convert.support.StringToCharacterConverter@5f2594f5</div><div>    <b>java.lang.String -&gt; java.lang.Enum</b> : org.springframework.core.convert.support.StringToEnumConverterFactory@1347a7be</div><div>    【<b>java.lang.String -&gt; java.lang.Number</b> : org.springframework.core.convert.support.<b>StringToNumberConverterFactory</b>@28a5e291】</div><div>    java.lang.String -&gt; java.time.Instant: org.springframework.format.datetime.standard.InstantFormatter@1eb74d34</div><div>    java.lang.String -&gt; java.util.Locale : org.springframework.core.convert.support.<b>StringToLocaleConverter</b>@6def03d3</div><div>    java.lang.String -&gt; java.util.Properties : org.springframework.core.convert.support.StringToPropertiesConverter@569d2e80</div><div>    java.lang.String -&gt; java.util.UUID : org.springframework.core.convert.support.StringToUUIDConverter@343b18b</div><div>    java.time.Instant -&gt; java.lang.String : org.springframework.format.datetime.standard.InstantFormatter@1eb74d34</div><div>    java.time.ZoneId -&gt; java.util.TimeZone : org.springframework.core.convert.support.ZoneIdToTimeZoneConverter@63b3b722</div><div>    java.util.Calendar -&gt; java.lang.Long : org.springframework.format.datetime.DateFormatterRegistrar$CalendarToLongConverter@1f07f950</div><div>    java.util.Calendar -&gt; java.util.Date : org.springframework.format.datetime.DateFormatterRegistrar$CalendarToDateConverter@3bfdcdf6</div><div>    java.util.Date -&gt; java.lang.Long : org.springframework.format.datetime.DateFormatterRegistrar$DateToLongConverter@19cfea5e</div><div>    java...</div></div><div><br/></div><div><hr/></div></div><div><img src="9、数据转换 & 数据格式化 & 数据校验_files/Image [1].png" type="image/png" style="height: auto;"/></div><div>validators负责数据校验工作；</div><div><br/></div><div><hr/></div><div><img src="9、数据转换 & 数据格式化 & 数据校验_files/Image [2].png" type="image/png" style="height: auto;"/></div><div>bindingResult负责保存以及解析数据绑定期间数据校验产生的错误；</div><div><br/></div><div><hr/></div><div><img src="9、数据转换 & 数据格式化 & 数据校验_files/Image [3].png" type="image/png" style="height: auto;"/></div><div><br/></div><div><hr/></div><div>1、自定义类型转换；</div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">     1)、步骤；</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">          ConversionService:：是一个接口；</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">               它里面有Converter（转换器）进行工作：</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">               </span></span><img src="9、数据转换 & 数据格式化 & 数据校验_files/Image [4].png" type="image/png" style="height: auto;"/></div><div>               </div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">         </span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">          2)、</span></span><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">Converter是ConversionService中的组件；</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">                    1、你的Converter得放进</span></span><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">ConversionService</span></span> <span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">中；</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">                    2、将WebDataBinder中的ConversionService设置成我们这个加了自定义类型转换器的</span></span><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">ConversionService；</span></span></div><div><font face="Arial Unicode MS" size="6">需要写的步骤</font></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">          1 )、实现Converter接口，写一个自定义的类型转换器；</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">          3）、配置出</span></span><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">ConversionService；</span></span></div><div><br/></div><div style="-en-codeblock: true; box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial;"><div><br/></div><div><br/></div><div>    &lt;!-- 告诉SpringMVC别用默认的ConversionService，</div><div>            而用我自定义的ConversionService、可能有我们自定义的Converter； --&gt;</div><div>    &lt;bean id=&quot;conversionService&quot; class=&quot;org.springframework.context.support.ConversionServiceFactoryBean&quot;&gt;</div><div>        &lt;!--converters转换器中添加我们自定义的类型转换器  --&gt;</div><div>        &lt;property name=&quot;converters&quot;&gt;</div><div>            &lt;set&gt;</div><div>                &lt;bean class=&quot;com.atguigu.component.MyStringToEmployeeConverter&quot;&gt;&lt;/bean&gt;</div><div>            &lt;/set&gt;</div><div>        &lt;/property&gt;</div><div>    &lt;/bean&gt;</div></div><div>                              4)、让SpringMVC用我们的ConversionService；</div><div><br/></div><div style="-en-codeblock: true; box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial;"><div>&lt;!-- conversion-service=&quot;conversionService&quot;：使用我们自己配置的类型转换组件 --&gt;</div><div>    &lt;mvc:annotation-driven conversion-service=&quot;conversionService&quot;&gt;&lt;/mvc:annotation-driven&gt;</div></div><div><br/></div><div><hr/></div><div>总结三步：</div><div>     1）、实现Converter接口，做一个自定义类型的转换器</div><div>     2）、将这个Converter配置在ConversionService中</div><div>               </div><div><br/></div><div style="-en-codeblock: true; box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial;"><div>&lt;!-- 告诉SpringMVC别用默认的ConversionService，</div><div>            而用我自定义的ConversionService、可能有我们自定义的Converter； --&gt;</div><div>    &lt;bean id=&quot;conversionService&quot; class=&quot;org.springframework.context.support.ConversionServiceFactoryBean&quot;&gt;</div><div>        &lt;!--converters转换器中添加我们自定义的类型转换器  --&gt;</div><div>        &lt;property name=&quot;converters&quot;&gt;</div><div>            &lt;set&gt;</div><div>                &lt;bean class=&quot;com.atguigu.component.MyStringToEmployeeConverter&quot;&gt;&lt;/bean&gt;</div><div>            &lt;/set&gt;</div><div>        &lt;/property&gt;</div><div>    &lt;/bean&gt;</div></div><div>     3）、告诉SpringNMVC使用这个ConversionService</div><div><br/></div><div style="-en-codeblock: true; box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial;"><div>&lt;!-- conversion-service=&quot;conversionService&quot;：使用我们自己配置的类型转换组件 --&gt;</div><div>    &lt;mvc:annotation-driven conversion-service=&quot;conversionService&quot;&gt;&lt;/mvc:annotation-driven&gt;</div></div><div>          4）、源码上WebDataBinder上的ConversionService组件就替换了；</div><div><img src="9、数据转换 & 数据格式化 & 数据校验_files/Image [5].png" type="image/png" style="height: auto;"/></div><div align="left" style="min-height: 18pt;"><div><br/></div><div style="-en-codeblock: true; box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial;"><div>ConversionService converters =</div><div>    java.lang.Boolean -&gt; java.lang.String : org.springframework.core.convert.support.ObjectToStringConverter@47d21368</div><div>    java.lang.Character -&gt; java.lang.Number : org.springframework.core.convert.support.CharacterToNumberFactory@3cdad94b</div><div>    java.lang.Character -&gt; java.lang.String : org.springframework.core.convert.support.ObjectToStringConverter@2a65d058</div><div>    java.lang.Enum -&gt; java.lang.String : org.springframework.core.convert.support.EnumToStringConverter@5b63b99f</div><div>    java.lang.Number -&gt; java.lang.Character : org.springframework.core.convert.support.NumberToCharacterConverter@1fee86c</div><div>    java.lang.Number -&gt; java.lang.Number : org.springframework.core.convert.support.NumberToNumberConverterFactory@281e80cc</div><div>    java.lang.Number -&gt; java.lang.String : org.springframework.core.convert.support.ObjectToStringConverter@7cd83820</div><div>    <span style="color: rgb(227, 0, 0);"><b>java.lang.String -&gt; com.atguigu.bean.Employee : com.atguigu.component.MyStringToEmployeeConverter@3dc22c7a</b></span></div><div>    java.lang.String -&gt; java.lang.Boolean : org.springframework.core.convert.support.StringToBooleanConverter@4331ec46</div><div>    java.lang.String -&gt; java.lang.Character : org.springframework.core.convert.support.StringToCharacterConverter@76a136a0</div><div>    java.lang.String -&gt; java.lang.Enum : org.springframework.core.convert.support.StringToEnumConverterFactory@31192e76</div><div>    java.lang.String -&gt; java.lang.Number : org.springframework.core.convert.support.StringToNumberConverterFactory@761ba575</div><div>    java.lang.String -&gt; java.util.Locale : org.springframework.core.convert.support.StringToLocaleConverter@17fc3d69</div><div>    java.lang.String -&gt; java.util.Properties : org.springframework.core.convert.support.StringToPropertiesConverter@38f0c949</div><div>    java.lang.String -&gt; java.util.UUID : org.springframework.core.convert.support.StringToUUIDConverter@8784d56</div><div>    java.time.ZoneId -&gt; java.util.TimeZone : org.springframework.core.convert.support.ZoneIdToTimeZoneConverter@c0a6ab8</div><div>    java.util.Locale -&gt; java.lang.String : org.springframework.core.convert.support.ObjectToStringConverter@406235ad</div><div>    java.util.Properties -&gt; java.lang.String : org.springframework.core.convert.support.PropertiesToStringConverter@7e193089</div><div>    java.util.TimeZone -&gt; java.time.ZoneId : org.springframework.core.convert.support.TimeZoneToZoneIdConverter@463abd52</div><div>    java.util.UUID -&gt; java.lang.String : org.springframework.core.convert.support.ObjectToStringConverter@59e6cea9</div><div>    org.springframework.core.convert.support.ArrayToArrayConverter@1a90e2f2</div><div>    org.springframework.core.convert.support.ArrayToCollectionConverter@6762ee5d</div><div>    org.springframework.core.convert.support.ArrayToObjectConverter@1aae2bbf</div><div>    org.springframework.core.convert.support.ArrayToStringConverter@15ee899f</div><div>    org.springframework.core.convert.support.ByteBufferConverter@2609c195</div><div>    org.springframework.core.convert.support.ByteBufferConverter@2609c195</div><div>    org.springframework.core.convert.support.CollectionToArrayConverter@50c81740</div><div>    org.springframework.core.convert.support.CollectionToCollectionConverter@75ece48f</div><div>    org.springframework.core.convert.support.CollectionToObjectConverter@59d26508</div><div>    org.springframework.core.convert.support.CollectionToStringConverter@1960bfcd</div><div>    org.springframework.core.convert.support.FallbackObjectToStringConverter@1137fd96</div><div>    org.springframework.core.convert.support.IdToEntityConverter@6a196118,org.springframework.core.convert.support.ObjectToObjectConverter@27400a7</div><div>    org.springframework.core.convert.support.MapToMapConverter@50cfc69</div><div>    org.springframework.core.convert.support.ObjectToArrayConverter@78a37337</div><div>    org.springframework.core.convert.support.ObjectToCollectionConverter@3a0b9fce</div><div>    org.springframework.core.convert.support.StringToArrayConverter@8747ea2</div><div>    org.springframework.core.convert.support.StringToCollectionConverter@324a432d</div></div><div><br/></div></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';"><br/></span></span></div><div><hr/></div><div align="left" style="min-height: 18pt;"><div><font color="#008080" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">&lt;</span></font><font color="#3F7F7F" face="Consolas" size="4"><span style="font-size:16pt; background:#d4d4d4">mvc:annotation-driven</span></font><font color="#008080" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">&gt;&lt;/</span></font><font color="#3F7F7F" face="Consolas" size="4"><span style="font-size:16pt; background:#d4d4d4">mvc:annotation-driven</span></font><font color="#008080" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">&gt;</span></font></div><div><img src="9、数据转换 & 数据格式化 & 数据校验_files/Image [6].png" type="image/png" style="height: auto;"/></div><div><br/></div><div>SpringMVC解析<font color="#3F7F7F" face="Consolas" size="4"><span style="font-size:16pt; background:#d4d4d4">mvc:annotation-driven表签到底做了哪些事情？</span></font></div><div><br/></div><div>解析这个标签添了好多东西；</div><div style="-en-codeblock: true; box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial;"><div>class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {</div><div><br/></div><div>    private static final boolean jsr303Present = ClassUtils.isPresent(</div><div>            &quot;javax.validation.Validator&quot;, AnnotationDrivenBeanDefinitionParser.class.getClassLoader());</div><div><br/></div><div>    private static final boolean jaxb2Present =</div><div>            ClassUtils.isPresent(&quot;javax.xml.bind.Binder&quot;, AnnotationDrivenBeanDefinitionParser.class.getClassLoader());</div><div><br/></div><div>    private static final boolean jackson2Present =</div><div>            ClassUtils.isPresent(&quot;com.fasterxml.jackson.databind.ObjectMapper&quot;, AnnotationDrivenBeanDefinitionParser.class.getClassLoader()) &amp;&amp;</div><div>                    ClassUtils.isPresent(&quot;com.fasterxml.jackson.core.JsonGenerator&quot;, AnnotationDrivenBeanDefinitionParser.class.getClassLoader());</div><div><br/></div><div>    private static final boolean jacksonPresent =</div><div>            ClassUtils.isPresent(&quot;org.codehaus.jackson.map.ObjectMapper&quot;, AnnotationDrivenBeanDefinitionParser.class.getClassLoader()) &amp;&amp;</div><div>                    ClassUtils.isPresent(&quot;org.codehaus.jackson.JsonGenerator&quot;, AnnotationDrivenBeanDefinitionParser.class.getClassLoader());</div><div><br/></div><div>    private static boolean romePresent =</div><div>            ClassUtils.isPresent(&quot;com.sun.syndication.feed.WireFeed&quot;, AnnotationDrivenBeanDefinitionParser.class.getClassLoader());</div><div><br/></div><div>    @Override</div><div>    public BeanDefinition parse(Element element, ParserContext parserContext) {</div><div>        Object source = parserContext.extractSource(element);</div><div><br/></div><div>        CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);</div><div>        parserContext.pushContainingComponent(compDefinition);</div><div><br/></div><div>        RuntimeBeanReference contentNegotiationManager = getContentNegotiationManager(element, source, parserContext);</div><div><br/></div><div>        RootBeanDefinition handlerMappingDef = new RootBeanDefinition(RequestMappingHandlerMapping.class);</div><div>        handlerMappingDef.setSource(source);</div><div>        handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);</div><div>        handlerMappingDef.getPropertyValues().add(&quot;order&quot;, 0);</div><div>        handlerMappingDef.getPropertyValues().add(&quot;contentNegotiationManager&quot;, contentNegotiationManager);</div><div>        String methodMappingName = parserContext.getReaderContext().registerWithGeneratedName(handlerMappingDef);</div><div>        if (element.hasAttribute(&quot;enable-matrix-variables&quot;) || element.hasAttribute(&quot;enableMatrixVariables&quot;)) {</div><div>            Boolean enableMatrixVariables = Boolean.valueOf(element.getAttribute(</div><div>                    element.hasAttribute(&quot;enable-matrix-variables&quot;) ? &quot;enable-matrix-variables&quot; : &quot;enableMatrixVariables&quot;));</div><div>            handlerMappingDef.getPropertyValues().add(&quot;removeSemicolonContent&quot;, !enableMatrixVariables);</div><div>        }</div><div><br/></div><div>        RuntimeBeanReference conversionService = getConversionService(element, source, parserContext);</div><div>        RuntimeBeanReference validator = getValidator(element, source, parserContext);</div><div>        RuntimeBeanReference messageCodesResolver = getMessageCodesResolver(element, source, parserContext);</div><div><br/></div><div>        RootBeanDefinition bindingDef = new RootBeanDefinition(ConfigurableWebBindingInitializer.class);</div><div>        bindingDef.setSource(source);</div><div>        bindingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);</div><div>        bindingDef.getPropertyValues().add(&quot;conversionService&quot;, conversionService);</div><div>        bindingDef.getPropertyValues().add(&quot;validator&quot;, validator);</div><div>        bindingDef.getPropertyValues().add(&quot;messageCodesResolver&quot;, messageCodesResolver);</div><div><br/></div><div>        ManagedList&lt;?&gt; messageConverters = getMessageConverters(element, source, parserContext);</div><div>        ManagedList&lt;?&gt; argumentResolvers = getArgumentResolvers(element, source, parserContext);</div><div>        ManagedList&lt;?&gt; returnValueHandlers = getReturnValueHandlers(element, source, parserContext);</div><div>        String asyncTimeout = getAsyncTimeout(element, source, parserContext);</div><div>        RuntimeBeanReference asyncExecutor = getAsyncExecutor(element, source, parserContext);</div><div>        ManagedList&lt;?&gt; callableInterceptors = getCallableInterceptors(element, source, parserContext);</div><div>        ManagedList&lt;?&gt; deferredResultInterceptors = getDeferredResultInterceptors(element, source, parserContext);</div><div><br/></div><div>        RootBeanDefinition handlerAdapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);</div><div>        handlerAdapterDef.setSource(source);</div><div>        handlerAdapterDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);</div><div>        handlerAdapterDef.getPropertyValues().add(&quot;contentNegotiationManager&quot;, contentNegotiationManager);</div><div>        handlerAdapterDef.getPropertyValues().add(&quot;webBindingInitializer&quot;, bindingDef);</div><div>        handlerAdapterDef.getPropertyValues().add(&quot;messageConverters&quot;, messageConverters);</div><div>        if (element.hasAttribute(&quot;ignore-default-model-on-redirect&quot;) || element.hasAttribute(&quot;ignoreDefaultModelOnRedirect&quot;)) {</div><div>            Boolean ignoreDefaultModel = Boolean.valueOf(element.getAttribute(</div><div>                    element.hasAttribute(&quot;ignore-default-model-on-redirect&quot;) ? &quot;ignore-default-model-on-redirect&quot; : &quot;ignoreDefaultModelOnRedirect&quot;));</div><div>            handlerAdapterDef.getPropertyValues().add(&quot;ignoreDefaultModelOnRedirect&quot;, ignoreDefaultModel);</div><div>        }</div><div>        if (argumentResolvers != null) {</div><div>            handlerAdapterDef.getPropertyValues().add(&quot;customArgumentResolvers&quot;, argumentResolvers);</div><div>        }</div><div>        if (returnValueHandlers != null) {</div><div>            handlerAdapterDef.getPropertyValues().add(&quot;customReturnValueHandlers&quot;, returnValueHandlers);</div><div>        }</div><div>        if (asyncTimeout != null) {</div><div>            handlerAdapterDef.getPropertyValues().add(&quot;asyncRequestTimeout&quot;, asyncTimeout);</div><div>        }</div><div>        if (asyncExecutor != null) {</div><div>            handlerAdapterDef.getPropertyValues().add(&quot;taskExecutor&quot;, asyncExecutor);</div><div>        }</div><div>        handlerAdapterDef.getPropertyValues().add(&quot;callableInterceptors&quot;, callableInterceptors);</div><div>        handlerAdapterDef.getPropertyValues().add(&quot;deferredResultInterceptors&quot;, deferredResultInterceptors);</div><div>        String handlerAdapterName = parserContext.getReaderContext().registerWithGeneratedName(handlerAdapterDef);</div><div><br/></div><div>        String uriCompContribName = MvcUriComponentsBuilder.MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME;</div><div>        RootBeanDefinition uriCompContribDef = new RootBeanDefinition(CompositeUriComponentsContributorFactoryBean.class);</div><div>        uriCompContribDef.setSource(source);</div><div>        uriCompContribDef.getPropertyValues().addPropertyValue(&quot;handlerAdapter&quot;, handlerAdapterDef);</div><div>        uriCompContribDef.getPropertyValues().addPropertyValue(&quot;conversionService&quot;, conversionService);</div><div>        parserContext.getReaderContext().getRegistry().registerBeanDefinition(uriCompContribName, uriCompContribDef);</div><div><br/></div><div>        RootBeanDefinition csInterceptorDef = new RootBeanDefinition(ConversionServiceExposingInterceptor.class);</div><div>        csInterceptorDef.setSource(source);</div><div>        csInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(0, conversionService);</div><div>        RootBeanDefinition mappedCsInterceptorDef = new RootBeanDefinition(MappedInterceptor.class);</div><div>        mappedCsInterceptorDef.setSource(source);</div><div>        mappedCsInterceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);</div><div>        mappedCsInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(0, (Object) null);</div><div>        mappedCsInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(1, csInterceptorDef);</div><div>        String mappedInterceptorName = parserContext.getReaderContext().registerWithGeneratedName(mappedCsInterceptorDef);</div><div><br/></div><div>        RootBeanDefinition exceptionHandlerExceptionResolver = new RootBeanDefinition(ExceptionHandlerExceptionResolver.class);</div><div>        exceptionHandlerExceptionResolver.setSource(source);</div><div>        exceptionHandlerExceptionResolver.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);</div><div>        exceptionHandlerExceptionResolver.getPropertyValues().add(&quot;contentNegotiationManager&quot;, contentNegotiationManager);</div><div>        exceptionHandlerExceptionResolver.getPropertyValues().add(&quot;messageConverters&quot;, messageConverters);</div><div>        exceptionHandlerExceptionResolver.getPropertyValues().add(&quot;order&quot;, 0);</div><div>        String methodExceptionResolverName =</div><div>                parserContext.getReaderContext().registerWithGeneratedName(exceptionHandlerExceptionResolver);</div><div><br/></div><div>        RootBeanDefinition responseStatusExceptionResolver = new RootBeanDefinition(ResponseStatusExceptionResolver.class);</div><div>        responseStatusExceptionResolver.setSource(source);</div><div>        responseStatusExceptionResolver.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);</div><div>        responseStatusExceptionResolver.getPropertyValues().add(&quot;order&quot;, 1);</div><div>        String responseStatusExceptionResolverName =</div><div>                parserContext.getReaderContext().registerWithGeneratedName(responseStatusExceptionResolver);</div><div><br/></div><div>        RootBeanDefinition defaultExceptionResolver = new RootBeanDefinition(DefaultHandlerExceptionResolver.class);</div><div>        defaultExceptionResolver.setSource(source);</div><div>        defaultExceptionResolver.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);</div><div>        defaultExceptionResolver.getPropertyValues().add(&quot;order&quot;, 2);</div><div>        String defaultExceptionResolverName =</div><div>                parserContext.getReaderContext().registerWithGeneratedName(defaultExceptionResolver);</div><div><br/></div><div>        parserContext.registerComponent(new BeanComponentDefinition(handlerMappingDef, methodMappingName));</div><div>        parserContext.registerComponent(new BeanComponentDefinition(handlerAdapterDef, handlerAdapterName));</div><div>        parserContext.registerComponent(new BeanComponentDefinition(uriCompContribDef, uriCompContribName));</div><div>        parserContext.registerComponent(new BeanComponentDefinition(exceptionHandlerExceptionResolver, methodExceptionResolverName));</div><div>        parserContext.registerComponent(new BeanComponentDefinition(responseStatusExceptionResolver, responseStatusExceptionResolverName));</div><div>        parserContext.registerComponent(new BeanComponentDefinition(defaultExceptionResolver, defaultExceptionResolverName));</div><div>        parserContext.registerComponent(new BeanComponentDefinition(mappedCsInterceptorDef, mappedInterceptorName));</div><div><br/></div><div>        // Ensure BeanNameUrlHandlerMapping (SPR-8289) and default HandlerAdapters are not &quot;turned off&quot;</div><div>        MvcNamespaceUtils.registerDefaultComponents(parserContext, source);</div><div><br/></div><div>        parserContext.popAndRegisterContainingComponent();</div><div><br/></div><div>        return null;</div><div>    }</div></div><div><br/></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(212, 212, 212);"><span style="color: rgb(63, 127, 127);"><br/></span></span></span></span></div><div><hr/></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(212, 212, 212);"><span style="color: rgb(63, 127, 127);">1、只要请求不好使就召唤mvc:annotation-driven；</span></span></span></span></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(212, 212, 212);"><span style="color: rgb(63, 127, 127);">1）、</span></span></span></span><font color="#008080" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">&lt;</span></font><font color="#3F7F7F" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">mvc:default-servlet-handler</span></font><font color="#008080" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">/&gt;  &lt;</span></font><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(212, 212, 212);"><span style="color: rgb(63, 127, 127);">mvc:annotation-driven/&gt;</span></span></span></span></div><div><font color="#3F7F7F" face="Consolas"><span style="font-size: 21px;">现象：</span></font></div><div><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(63, 127, 127);">     1）、都没配？动态资源（@RequestMapping映射的资源能访问，静态资源（.html,.js,.img））</span></span></span></div><div><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(63, 127, 127);">     HandlerMapping：</span></span></span></div><div>                              <img src="9、数据转换 & 数据格式化 & 数据校验_files/Image [7].png" type="image/png" style="height: auto;"/></div><div><img src="9、数据转换 & 数据格式化 & 数据校验_files/Image [8].png" type="image/png" style="height: auto;"/></div><div>               动态能访问：</div><div align="left" style="min-height: 18pt;"><div><font color="#010101" face="Consolas" size="4"><span style="font-size:16pt">DefaultAnnotationHandlerMapping中的handlerMap中保存了每一个资源的映射信息；</span></font></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="color: rgb(1, 1, 1);">     静态不能访问：</span></span></span></div><div><font color="#010101" face="Consolas"><span style="font-size: 21px;">就是handlerMap中没有保存静态资源映射的请求，</span></font></div><div><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(1, 1, 1);">     HandlerAdapter：方法执行的适配器；</span></span></span></div><div><img src="9、数据转换 & 数据格式化 & 数据校验_files/Image [9].png" type="image/png" style="height: auto;"/></div><div align="left" style="min-height: 18pt;"><div><font color="#010101" face="Consolas" size="4"><span style="font-size:16pt">AnnotationMethodHandlerAdapter:帮我们执行目标方法；过时的；</span></font></div></div></div><div><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(63, 127, 127);"><br/></span></span></span></div><div><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(63, 127, 127);">     2）、加上</span></span></span><font color="#008080" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">&lt;</span></font><font color="#3F7F7F" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">mvc:default-servlet-handler</span></font><font color="#008080" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">/&gt;，</span></font><font color="#008080" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">&lt;</span></font><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(212, 212, 212);"><span style="color: rgb(63, 127, 127);">mvc:annotation-driven/&gt;</span></span></span></span> ，<font color="#008080" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">不加静态资源ok，动态资源完蛋</span></font></div><div><font color="#008080" face="Consolas"><span style="font-size: 21px;">HandlerMapping中  变化；</span></font></div><div><img src="9、数据转换 & 数据格式化 & 数据校验_files/Image [10].png" type="image/png" style="height: auto;"/></div><div><br/></div><div><br/></div><div><font color="#010101" face="Consolas" size="4"><span style="font-size:16pt">动态不能访问：DefaultAnnotationHandlerMapping没有了；用</span></font><font color="#010101" face="Consolas" size="4"><span style="font-size:16pt">SimpleUrlHandlerMapping替换了，他的作咏就是将所有请求直接交给tomcat；</span></font></div><div><font color="#010101" face="Consolas"><span style="font-size: 21px;">静态能访问的原因：</span></font><font color="#010101" face="Consolas" size="4"><span style="font-size:16pt">SimpleUrlHandlerMapping把所有请求都映射给tomcat；</span></font></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="color: rgb(1, 1, 1);"><br/></span></span></span></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="color: rgb(1, 1, 1);"><br/></span></span></span></div><div><font color="#010101" face="Consolas"><span style="font-size: 21px;">HandlerAdapter：</span></font></div><div><img src="9、数据转换 & 数据格式化 & 数据校验_files/Image [11].png" type="image/png" style="height: auto;"/></div><div><font color="#010101" face="Consolas" size="4"><span style="font-size:16pt">AnnotationMethodHandlerAdapter都没有了；</span></font></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="color: rgb(1, 1, 1);"><br/></span></span></span></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="color: rgb(1, 1, 1);"><br/></span></span></span></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="color: rgb(1, 1, 1);"><br/></span></span></span></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(232, 242, 254);"><span style="color: rgb(0, 128, 128);">     3）、加上</span></span></span></span><font color="#008080" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">&lt;</span></font><font color="#3F7F7F" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">mvc:default-servlet-handler</span></font><font color="#008080" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">/&gt;，加上</span></font><font color="#008080" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">&lt;</span></font><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(212, 212, 212);"><span style="color: rgb(63, 127, 127);">mvc:annotation-driven/&gt;；才都能访问</span></span></span></span></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(212, 212, 212);"><span style="color: rgb(63, 127, 127);">HandlerMapping变化</span></span></span></span></div><div><img src="9、数据转换 & 数据格式化 & 数据校验_files/Image [12].png" type="image/png" style="height: auto;"/></div><div align="left" style="min-height: 18pt;"><div><font color="#010101" face="Consolas" size="4"><span style="font-size:16pt">RequestMappingHandlerMapping:动态资源可以访问</span></font></div><div><img src="9、数据转换 & 数据格式化 & 数据校验_files/Image [13].png" type="image/png" style="height: auto;"/></div><div><span style="font-size: 19px;"><b>handleMethods属性保存了每一个请求用哪个方法来处理；</b></span></div><div><br/></div><div><br/></div></div><div><span style="color: rgb(227, 0, 0);"><span style="font-size: 19px;">SimpleUrlHandlerMapping：将请求直接交给tomcat；有他，静态资源就没问题；</span></span></div><div><br/></div><div><span style="font-size: 24px;">HandlerAdapter：</span></div><div><img src="9、数据转换 & 数据格式化 & 数据校验_files/Image [14].png" type="image/png" style="height: auto;"/></div><div>原来的</div><div><font color="#010101" face="Consolas" size="4"><span style="font-size:16pt">AnnotationMethodHandlerAdapter；被换成</span></font><font color="#010101" face="Consolas" size="4"><span style="font-size:16pt">RequestMappingHandlerAdapter；</span></font></div><div><font color="#010101" face="Consolas"><span style="font-size: 21px;">确定参数都用成解析器了</span></font></div><div><img src="9、数据转换 & 数据格式化 & 数据校验_files/Image [15].png" type="image/png" style="height: auto;"/></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(212, 212, 212);"><span style="color: rgb(63, 127, 127);"><br/></span></span></span></span></div><div><hr/></div><div><font color="#3F7F7F" face="Consolas"><span style="font-size: 21px;">格式化：</span></font></div><div><font color="#3F7F7F" face="Consolas"><span style="font-size: 21px;">页面提交的数据格式如果不正确，就是400；</span></font></div><div><font color="#3F7F7F" face="Consolas"><span style="font-size: 21px;">日期格式：2017-12-19</span></font></div><div align="left" style="min-height: 18pt;"><div><font color="#2A00FF" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe"><i>ConversionServiceFactoryBean:创建的ConversionService组件是没有格式化器存在的；</i></span></font></div><div><i><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(232, 242, 254);"><span style="color: rgb(42, 0, 255);"><br/></span></span></span></span></i></div><div><hr/></div><div><font color="#2A00FF" face="Consolas"><span style="font-size: 21px;"><i>数据校验；</i></span></font></div><div><font color="#2A00FF" face="Consolas"><span style="font-size: 21px;"><i>只做前端校验是不安全的；</i></span></font></div><div><font color="#2A00FF" face="Consolas"><span style="font-size: 21px;"><i>在重要数据一定要加上后端验证；</i></span></font></div><div><i><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(42, 0, 255);">1）、可以写程序将我们每一个数据取出进行校验，如果失败直接来到添加页面，提示其重新填写；x</span></span></span></i></div><div><i><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(42, 0, 255);">2）、SpringMVC；可以JSR303来做数据校验</span></span></span></i></div><div><i><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(42, 0, 255);">     JDBC:规范---实现（各个厂商的驱动包）</span></span></span></i></div><div><i><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(42, 0, 255);">     JSR303：规范-----Hibernate Validator（第三方校验框架）</span></span></span></i></div><div><i><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(42, 0, 255);">          </span></span></span></i></div><div><i><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(42, 0, 255);">3）、如何快速的进行后端校验；</span></span></span></i></div><div><i><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(42, 0, 255);">     1）、导入校验框架的jar包；</span></span></span></i></div><div><i><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(42, 0, 255);">      有几个带el的jar不导入；tomcat中有；如果tomcat的版本是</span></span></span></i></div><div><i><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(42, 0, 255);">          7.0以下；tomcat7.0以上el表达式比较强大；</span></span></span></i></div><div><i><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(42, 0, 255);">          如果是7.0以下将带el的几个jar放在tomcat的lib文件夹下；<br/></span></span></span></i></div><div align="left" style="min-height: 18pt;"><font face="Consolas" size="4"><span style="font-size:16pt">    hibernate-validator-5.0</span><span style="font-size:16pt"><u>.0</u></span><span style="font-size:16pt">.</span><span style="font-size:16pt"><u>CR2</u></span><span style="font-size:16pt">.jar</span></font></div><div align="left" style="min-height: 11pt;"><div><font face="Consolas" size="4"><span style="font-size:16pt">    </span><span style="font-size:16pt"><u>hibernate</u></span><span style="font-size:16pt">-validator-annotation-processor-5.0</span><span style="font-size:16pt"><u>.0</u></span><span style="font-size:16pt">.CR2.</span><span style="font-size:16pt"><u>jar</u></span></font></div><div align="left" style="min-height: 18pt;"><div><font face="Consolas" size="4"><span style="font-size:16pt">    classmate-0.8</span><span style="font-size:16pt"><u>.0</u></span><span style="font-size:16pt">.</span><span style="font-size:16pt"><u>jar</u></span></font></div></div><div align="left" style="min-height: 18pt;"><font face="Consolas" size="4"><span style="font-size:16pt">    </span><span style="font-size:16pt"><u>jboss</u></span><span style="font-size:16pt">-</span><span style="font-size:16pt"><u>logging</u></span><span style="font-size:16pt">-3.1</span><span style="font-size:16pt"><u>.1</u></span><span style="font-size:16pt">.</span><span style="font-size:16pt"><u>GA</u></span><span style="font-size:16pt">.jar</span></font></div><div align="left" style="min-height: 18pt;"><div><font face="Consolas" size="4"><span style="font-size:16pt">    </span><span style="font-size:16pt"><u>validation</u></span><span style="font-size:16pt">-api-1.1</span><span style="font-size:16pt"><u>.0</u></span><span style="font-size:16pt">.CR1.</span><span style="font-size:16pt"><u>jar</u></span></font></div><div><u><span style="font-size: 16pt;"><span style="font-family: Consolas;"><br/></span></span></u></div></div></div><div><i><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(42, 0, 255);">     2）、只需要给javaBean的属性添加上校验注解</span></span></span></i></div><div>                         <img src="9、数据转换 & 数据格式化 & 数据校验_files/Image [16].png" type="image/png"/></div><div>               </div></div><div><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(63, 127, 127);">      3</span></span></span><i><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(42, 0, 255);">）、在SpringMVC封装对象的时候，告诉SpringMVC这个javaBean需要校验</span></span></span></i></div><div><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(63, 127, 127);">         </span></span></span><div align="left" style="min-height: 18pt;"><div><font color="#7F0055" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe"><b>          public</b></span></font> <font face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">String addEmp(</span></font><font color="#646464" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">@Valid</span></font> <font face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">Employee employee) {</span></font></div></div></div><div><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(63, 127, 127);">      <span style="color: rgb(42, 0, 255);"><i>4</i></span></span></span></span><i><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(42, 0, 255);">）、如何知道校验结果；</span></span></span></i></div><div><i><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(42, 0, 255);">          给需要校验的javaBean后面紧跟一个BindingResult。这个BindingResult就是封装前一个bean的校验结果；</span></span></span></i></div><div><i><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(42, 0, 255);">       5）、根据不同的校验结果决定怎么办？</span></span></span></i></div><div><i><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(42, 0, 255);"><br/></span></span></span></i></div><div><i><span style="font-size: 21px;"><span style="font-family: Consolas;"><span style="color: rgb(42, 0, 255);">       6）、来到页面使用form:errors取出错误信息即可；</span></span></span></i></div><div><img src="9、数据转换 & 数据格式化 & 数据校验_files/Image [17].png" type="image/png"/></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(212, 212, 212);"><span style="color: rgb(63, 127, 127);"><br/></span></span></span></span></div><div><hr/></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(212, 212, 212);"><span style="color: rgb(63, 127, 127);">1）、原生的表单怎么办？</span></span></span></span></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(212, 212, 212);"><span style="color: rgb(63, 127, 127);">     将错误放在请求域中就行了；</span></span></span></span></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(212, 212, 212);"><span style="color: rgb(63, 127, 127);"><br/></span></span></span></span></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(212, 212, 212);"><span style="color: rgb(63, 127, 127);">2）、国际化定制自己的错误消息显示；</span></span></span></span></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(212, 212, 212);"><span style="color: rgb(63, 127, 127);">     编写国际化的文件；</span></span></span></span></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(212, 212, 212);"><span style="color: rgb(63, 127, 127);">          errors_zh_CN.properties</span></span></span></span></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(212, 212, 212);"><span style="color: rgb(63, 127, 127);">          errors_en_US.properties</span></span></span></span></div><div align="left" style="min-height: 18pt;"><div><font face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">key=</span></font><font color="#2A00FF" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe"><u>lastname</u></span></font> <font color="#2A00FF" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">between</span></font> <font color="#2A00FF" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">6</span></font> <font color="#2A00FF" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">and</span></font> <font color="#2A00FF" face="Consolas" size="4"><span style="font-size:16pt; background:#e8f2fe">18</span></font></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(232, 242, 254);"><span style="color: rgb(42, 0, 255);">          key有规定；</span></span></span></span></div><div align="left" style="min-height: 18pt;"><div><br/></div><div style="-en-codeblock: true; box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial;"><div>Field error in object 'employee' on field 'birth':</div><div>     rejected value [Aa];</div><div>     <span style="color: rgb(227, 0, 0);">codes</span> [typeMismatch.employee.birth,typeMismatch.birth,typeMismatch.java.util.Date,typeMismatch];</div><div>     arguments [org.springframework.context.support.DefaultMessageSourceR</div></div><div><br/></div></div></div><div align="left" style="min-height: 18pt;"><div><br/></div><div style="-en-codeblock: true; box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial;"><div>Field error in object 'employee' on field 'email':</div><div>     rejected value [a];</div><div>     <span style="color: rgb(255, 0, 0);">codes</span> [Email.employee.email,Email.email,Email.java.lang.String,Email];</div><div>      arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [employee.email,email]; arguments []; default message [email],[Ljavax.validation.constraints.Pattern$Flag;@7f9bea7,.*];</div><div>     default message [不是一个合法的电子邮件地址]</div></div><div><br/></div><div>每一个字段发生错误以后，都会有自己的错误代码；国际化文件中错误消息的key必须对应一个错误代码</div><div><hr/></div><div> <span style="color: rgb(255, 0, 0);">codes</span></div><div>     [</div><div>          Email.employee.email,      校验规则.隐含模型中这个对象的key.对象的属性</div><div>          Email.email,                       校验规则.属性名</div><div>          Email.java.lang.String,      校验规则.属性类型</div><div>          Email</div><div>    ];</div><div>1、如果是隐含模型中employee对象的email属性字段发生了@Email校验错误，就会生成 Email.employee.email;</div><div>2、 Email.email：所有的email属性只要发生了@Email错误；</div><div>3、 Email.java.lang.String,:只要是String类型发生了@Email错误</div><div>4、Email：只要发生了@Email校验错误；</div></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(212, 212, 212);"><span style="color: rgb(63, 127, 127);"><br/></span></span></span></span></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(212, 212, 212);"><span style="color: rgb(63, 127, 127);">1、先编写国际化配置文件</span></span></span></span></div><div><img src="9、数据转换 & 数据格式化 & 数据校验_files/Image [18].png" type="image/png"/></div><div>2、让SpringMVC管理国际化资源文件；</div><div align="left" style="min-height: 18pt;"><font color="#3F5FBF" face="Consolas" size="4"><span style="font-size:16pt">&lt;!-- 管理国际化资源文件 --&gt;</span></font></div><div align="left" style="min-height: 18pt;"><font face="Consolas" size="4"><span style="font-size:16pt">    </span></font><font color="#008080" face="Consolas" size="4"><span style="font-size:16pt">&lt;</span></font><font color="#3F7F7F" face="Consolas" size="4"><span style="font-size:16pt">bean</span></font> <font color="#7F007F" face="Consolas" size="4"><span style="font-size:16pt">id</span></font><font face="Consolas" size="4"><span style="font-size:16pt">=</span></font><font color="#2A00FF" face="Consolas" size="4"><span style="font-size:16pt"><i>&quot;messageSource&quot;</i></span></font> <font color="#7F007F" face="Consolas" size="4"><span style="font-size:16pt">class</span></font><font face="Consolas" size="4"><span style="font-size:16pt">=</span></font><font color="#2A00FF" face="Consolas" size="4"><span style="font-size:16pt"><i>&quot;org.springframework.context.support.ResourceBundleMessageSource&quot;</i></span></font><font color="#008080" face="Consolas" size="4"><span style="font-size:16pt">&gt;</span></font></div><div align="left" style="min-height: 18pt;"><font face="Consolas" size="4"><span style="font-size:16pt">        </span></font><font color="#008080" face="Consolas" size="4"><span style="font-size:16pt">&lt;</span></font><font color="#3F7F7F" face="Consolas" size="4"><span style="font-size:16pt">property</span></font> <font color="#7F007F" face="Consolas" size="4"><span style="font-size:16pt">name</span></font><font face="Consolas" size="4"><span style="font-size:16pt">=</span></font><font color="#2A00FF" face="Consolas" size="4"><span style="font-size:16pt"><i>&quot;basename&quot;</i></span></font> <font color="#7F007F" face="Consolas" size="4"><span style="font-size:16pt">value</span></font><font face="Consolas" size="4"><span style="font-size:16pt">=</span></font><font color="#2A00FF" face="Consolas" size="4"><span style="font-size:16pt"><i>&quot;errors&quot;</i></span></font><font color="#008080" face="Consolas" size="4"><span style="font-size:16pt">&gt;&lt;/</span></font><font color="#3F7F7F" face="Consolas" size="4"><span style="font-size:16pt">property</span></font><font color="#008080" face="Consolas" size="4"><span style="font-size:16pt">&gt;</span></font></div><div align="left" style="min-height: 18pt;"><div><font face="Consolas" size="4"><span style="font-size:16pt">    </span></font><font color="#008080" face="Consolas" size="4"><span style="font-size:16pt">&lt;/</span></font><font color="#3F7F7F" face="Consolas" size="4"><span style="font-size:16pt">bean</span></font><font color="#008080" face="Consolas" size="4"><span style="font-size:16pt">&gt;</span></font></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="color: rgb(0, 128, 128);">3、来到页面取值</span></span></span></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="color: rgb(0, 128, 128);">4、高级国际化？</span></span></span></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="color: rgb(0, 128, 128);">     动态传入消息参数；</span></span></span></div><div><img src="9、数据转换 & 数据格式化 & 数据校验_files/Image [19].png" type="image/png"/></div></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(212, 212, 212);"><span style="color: rgb(63, 127, 127);">{0}：永远都是当前属性名；</span></span></span></span></div><div><span style="font-size: 16pt;"><span style="font-family: Consolas;"><span style="background-color: rgb(212, 212, 212);"><span style="color: rgb(63, 127, 127);">{1}、{2}</span></span></span></span></div></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';"><br/></span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';"><br/></span></span></div><div><hr/></div><div><font face="Arial Unicode MS" size="6"><span>ajax；</span></font></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">1、SpringMVC快速的完成ajax功能？</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">     1）、返回数据是json就ok；</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">     2）、页面,$.ajax()；</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">2、原生javaWeb：</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">     1）、导入GSON；</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">     2）、返回的数据用GSON转成json</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">     3）、写出去；</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">3、SpringMVC-ajax：</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">     1、导包</span></span></div><div align="left" style="min-height: 18pt;"><font face="Consolas" size="4"><span style="font-size:16pt"><u>jackson</u></span><span style="font-size:16pt">-annotations-2.1.5.jar</span></font></div><div align="left" style="min-height: 18pt;"><font face="Consolas" size="4"><span style="font-size:16pt"><u>jackson</u></span><span style="font-size:16pt">-core-2.1.5.jar</span></font></div><div align="left" style="min-height: 18pt;"><div><font face="Consolas" size="4"><span style="font-size:16pt"><u>jackson</u></span><span style="font-size:16pt">-</span><span style="font-size:16pt"><u>databind</u></span><span style="font-size:16pt">-2.1.5.jar</span></font></div></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">     2、写配置</span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';">     3、测试<br/></span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';"><br/></span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';"><br/></span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';"><br/></span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';"><br/></span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';"><br/></span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';"><br/></span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';"><br/></span></span></div><div><span style="font-size: 26px;"><span style="font-family: 'Arial Unicode MS';"><br/></span></span></div></span>
</div></body></html> 